package github.kawaiior.yuanchuxiuzhen.common.item.misc;

import github.kawaiior.yuanchuxiuzhen.common.item.fire.StrangeFireItem;
import github.kawaiior.yuanchuxiuzhen.core.init.itemgroup.YcxzGroup;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;

public class StrangeFireBag extends Item {
    public StrangeFireBag() {
        super(new Properties().group(YcxzGroup.YCXZ_GROUP).maxStackSize(1));
    }

    private void openBag(ItemStack stack, PlayerEntity player){
        if (random.nextInt(100) < 90){
            if (random.nextBoolean()){
                player.addItemStackToInventory(new ItemStack(StrangeFireItem.getYangStrangeFire(random.nextInt(9)+1)));
            }else {
                player.addItemStackToInventory(new ItemStack(StrangeFireItem.getYinStrangeFire(random.nextInt(9)+1)));
            }
        }else {
            // TODO: send message
        }
        stack.shrink(1);
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        if (!worldIn.isRemote){
            ItemStack itemstack = playerIn.getHeldItem(handIn);
            if (itemstack.getItem() instanceof StrangeFireBag){
                openBag(itemstack, playerIn);
            }
        }
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }
}
